package string;

/**
 * @author Huangjin
 * @version 1.0
 * describe:String和StringBuilder的对比
 * @date 2023/2/28 15:53
 */
public class StringAndStringBuilderDemo {
    public static void main(String[] args) {
        StringBuilder builder = new StringBuilder("a");
        for (int i = 0; i < 10000000; i++) {
            //每次修改都会在内存中分配新的对象
            builder.append("i");
//            System.out.println(builder.append("i"));

        }
        System.out.println(builder);
        System.out.println("执行完毕");

        /*
        //String不适合频繁修改内容（效率低）
        String s= "a";
        for (int i = 0; i < 10000000; i++) {
            //每次修改都会在内存中分配新的对象
            s = s+i;

        }
        System.out.println("执行完毕");

         */
    }
}
